package backstage.app.controller.pt;

 

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import backstage.app.entity.ConstionParent;
import backstage.app.mapper.ConstionParentMapper;
import backstage.app.mapper.ConstitutionMapper;
import backstage.app.respont.RespontDateJson;
import backstage.app.service.impl.util.ConstionParentUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("${spring.application.name}/constionparent/api")
@Api("体质测试主表-控制器")
public class ConstionParentController {
	@Autowired
	private ConstionParentMapper constionParentMapper;
	private static final Logger logger = (Logger) LoggerFactory.getLogger(ConstionParentController.class);
	@Autowired
	private ConstionParentUtil constionParentUtil;
	@Autowired
	private ConstitutionMapper constitutionMapper;
	
	@PostMapping("/list")
	@ApiOperation(value="获取体质测试类型集合")
	public List<ConstionParent>list(){
		List<ConstionParent>list=constionParentMapper.selectList(null);
		for (ConstionParent constionParent : list) {
			 int total= constitutionMapper.selectByCpIdByCount(constionParent.getCid());
			 constionParent.setTotal(total);
		}
		return list;
	}
	
	@PostMapping("/byCid")
	@ApiOperation("根据cid执行以下的")
	public RespontDateJson<?>getByCid(@RequestParam(value="cid",required = true)Integer cid){
		ConstionParent constionParent = null;
		try {
			constionParent=constionParentMapper.selectByPrimaryKey(cid);
		} catch (Exception e) {
			// TODO: handle exception
			logger.error("select throw exception on  {}",constionParent.getCid());
		}
		return RespontDateJson.ok(constionParent, "查询成功");
	}
	
	
	 
	@PostMapping("/deleteByCid")
	@ApiOperation("根据cid删除")
	public RespontDateJson<?>deleteByCid(@RequestParam(value="cid",required = true)Integer cid){
		int resut =-1;
		try {
			resut=constionParentMapper.deleteByPrimaryKey(cid);
		} catch (Exception e) {
			// TODO: handle exception
			logger.error("delete throw exception for cid ={}",cid);
		}
		return RespontDateJson.ok(resut, "删除成功");
	}
	
	
	
	
	@PostMapping("/inser")
	@ApiOperation("添加类型")
	public RespontDateJson<?>inser(
			//标题信息
			@RequestParam(value="content",required = true)String content,
			@RequestParam(value="height",required = false)String height,
			@RequestParam(value="width",required = false)String width,
			@RequestParam(value="abduction",required = false)String abduction,
			@RequestParam(value="fingerSpan",required = false)String fingerSpan,
			//大文本
			@RequestParam(value="singForward",required = false)String singForward,
			@RequestParam(value="roundTrip",required = false)String roundTrip,
			@RequestParam(value="courtSprint",required = false)String courtSprint,
			@RequestParam(value="restrtedArea",required = false)String restrtedArea,
			@RequestParam(value="klingWing",required = false)String klingWing,
			@RequestParam(value="verticalJump",required = false)String verticalJump,
			@RequestParam(value="continJump",required = false)String continJump){
		return constionParentUtil.inser(content, height, width, abduction, fingerSpan, singForward, roundTrip, courtSprint, restrtedArea, klingWing, verticalJump, continJump);
	}
	
	
	
	
}
